<?php
/**
* @author Bimal Poudel
* @copyright since 2006, Bimal Poudel
* @package Smarty Framework
* @support http://www.odesk.com/users/~~dd91d11caed0cdce
* @contact http://www.sanjaal.com
* @company Sanjaal Corps
*/

# Created on: 2012-04-08 12:50:53 506

/**
* Pokes uses and registers that they are online
*/

# FQURL/users-poke.php?username=bimal@bim.al&password=bimal321
# FQURL/users-poke.php?id=3&code=201204081355145138

#print_r($_GET);

$user_id = $variable->get('id', 'integer', 0);
$user_code = $variable->get('code', 'string', '');

$users = new users();
$user = $users->details($user_id);
#print_r($user);

# Validate the user
if(!$user) die('Invalid poke - reset ID/code first.');
if($user_code != $user['user_code']) die('Code mismatched to poke this user.');

$subdomain_id=230;

$fc = __BASE__.'/pokes-logs/'.date('YmdHis').mt_rand(1000, 9999).'.txt';
$client = print_r($_SERVER, true);
file_put_contents($fc, $client);

function value($index)
{
	$value = isset($_SERVER[$index])?addslashes($_SERVER[$index]):'';
	return $value;
}

$browser_accept=value('HTTP_ACCEPT');
$browser_encoding=value('HTTP_ACCEPT_ENCODING');
$browser_language=value('HTTP_ACCEPT_LANGUAGE');
$browser_ip = value('REMOTE_ADDR');
$browser_isp = gethostbyaddr($browser_ip);
$browser_browser = value('HTTP_USER_AGENT');
$http_host = value('HTTP_HOST');
$browser_referer = value('HTTP_REFERER');
$browser_querystring = value('QUERY_STRING');
mysql_select_db('smarty_framework', mysql_connect('localhost', 'root', 'toor'));
$poker_sql="
INSERT INTO `pokes_collections`(
	`user_id`,
	`subdomain_id`,`added_on`,`fixed_on`,`modified_on`,`modified_counter`,
	`is_active`,`is_approved`,
	`http_host`,`browser_ip`,`browser_isp`,
	`browser_language`,`browser_encoding`,`browser_accept`,`browser_browser`,
	`browser_profile`, `profile_wap`,`browser_referer`,`browser_querystring`
) VALUES (
	{$user_id},
	'{$subdomain_id}',UNIX_TIMESTAMP(CURRENT_TIMESTAMP()),'0','0','0',
	'Y','Y',
	'{$http_host}','{$browser_ip}','{$browser_isp}',
	'{$browser_language}','{$browser_encoding}','{$browser_accept}','{$browser_browser}',
	'','','{$browser_referer}','{$browser_querystring}'
);";
mysql_query($poker_sql);

# Auto data cleaning (do not apply in InnoDB
$poker_user_sql="DELETE FROM pokes_collections WHERE user_id={$user_id} AND added_on <= (UNIX_TIMESTAMP(CURRENT_TIMESTAMP())-{$user['user_history']});";
mysql_query($poker_sql);

# Mark the registered user
$poker_user_sql="UPDATE pokes_users SET poked_on=UNIX_TIMESTAMP(CURRENT_TIMESTAMP()), user_pokescounter=user_pokescounter+1 WHERE user_id={$user_id};";
mysql_query($poker_sql);

if(!preg_match('/curl/', $browser_browser))
{
	# Show only to the real browsers, not for automated CURL requests
	echo 'I am just poked on!';
}
?>